package com.itheima;

import com.itheima.utils.DateUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class DateDemo {

    public static void main(String[] args) throws Exception {

        List<String> months = new ArrayList<>();

        //创建日历
        Calendar calendar = Calendar.getInstance();
        //返回12个月以前
        calendar.add(Calendar.MONTH,-12);
        for (int i = 0; i < 12; i++) {
            String str = DateUtils.parseDate2String(calendar.getTime(),"yyyy-MM");
            //前移一个月
            calendar.add(Calendar.MONTH,1);
            months.add(str);
        }

        for (String month : months) {
            System.out.println(month);
        }

    }

}
